#******************************************************************
#
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# 'hippomocks' script to check if Hippo Mocks Unit Test library is installed.
# If not, get it and install it
#
##

import os, sys

Import('env')

target_os = env.get('TARGET_OS')
src_dir = env.get('SRC_DIR')

if target_os in ['linux', 'windows']:
    print('*** Checking for installation of hippomocks ***')
    hippomocks_version = '5.0'
    hippomocks_revision = 'v' + hippomocks_version
    hippomocks_src_dir = src_dir + '/extlibs/hippomocks/hippomocks-' + hippomocks_version
    hippomocks_dest_dir = src_dir + '/extlibs/hippomocks/hippomocks'
    hippomocks_zip_file = src_dir + '/extlibs/hippomocks/' + hippomocks_revision + '.zip'
    hippomocks_url = 'https://github.com/dascandy/hippomocks/archive/' + hippomocks_revision + '.zip'
    if not os.path.exists(hippomocks_dest_dir):
        if not os.path.exists(hippomocks_zip_file):
            hippomocks_zip = env.Download(hippomocks_zip_file, hippomocks_url)
        else:
            hippomocks_zip = hippomocks_zip_file
        print('hippomocks: Unzipping %s to %s' % (hippomocks_zip_file,
                                                  hippomocks_dest_dir))
        env.UnpackAll(hippomocks_src_dir, hippomocks_zip)
        os.rename(hippomocks_src_dir, hippomocks_dest_dir)
